<!doctype html>
<!--suppress ALL -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JWT</title>
</head>
<body>

    <input type="text" name="username" id="username">
    <input type="password" name="password" id="password">
    <button class="sub">提交</button>
    <input type="reset" value="重置">

<div class="power">
    确认是否有权限
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
  $('.sub').click(function(){
      $.ajax({
          type:'GET',
          url: "./login.php",
          data:{
              username:$('#username').val(),
              password: $('#password').val()
          },
          success:function (e) {
              localStorage.setItem('token',e);
              console.log(localStorage.getItem('token'));
          }
      })
  })

  $('.power').click(function(){

      if (localStorage.getItem('token') == null) {
          alert('请登录获取token')

          return false;
      }
      $.ajax({
          type:'GET',
          url: "./index.php",
          headers:{
              token:localStorage.getItem('token')
          },
          success:function (e) {
          	console.log(e)
          }
      })
  })

</script>
</html>
